(function(window){
    // constants
    var CONST = {
        NodeType: {
            ELEMENT_NODE: 1,
            ATTRIBUTE_NODE: 2,
            TEXT_NODE: 3,
            CDATA_SECTION_NODE: 4,
            ENTITY_REFERENCE_NODE: 5,
            ENTITY_NODE: 6,
            PROCESSING_INSTRUCTION_NODE: 7,
            COMMENT_NODE: 8,
            DOCUMENT_NODE: 9,
            DOCUMENT_TYPE_NODE: 10,
            DOCUMENT_FRAGMENT_NODE: 11,
            NOTATION_NODE: 12
        }
    };

    init = (function(){
        freeze(CONST.NodeType);
        if (typeof console == "undefined") {
            this.console = {log: function() {}};
        }
        alert(CONST.NodeType.ATTRIBUTE_NODE);
    });

    freeze = (function(object){
        Object.freeze(object);
        for (property in object) {
            if (!object.hasOwnProperty(property) || !(typeof object === "object") || Object.isFrozen(object)) {
                continue;
            }
            freeze(property);
        }
    });

//    CONST.NodeType.ATTRIBUTE_NODE = 1000;
//    console.log(CONST.NodeType.ATTRIBUTE_NODE);
//    alert(CONST.NodeType.ATTRIBUTE_NODE);

    // will return undefined in case not found or selector is not an element node or a document node.
    $ = (function(selector, context, result){
//        alert(selector);
        var context = context || document;
        console.log(context.NodeType);
        if (!selector || typeof selector !== "string") {
            return result;
        }

        if (context.NodeType !== CONST.NodeType.ELEMENT_NODE && context.NodeType !== CONST.NodeType.DOCUMENT_NODE) {
            return result;
        }
        else {
            console.log("found");
            return context.getElementById(selector);
        }
    });

    $.abc = function(selector){
        return $(selector);
    }

//    Dummy = function(selector) {
//        alert(selector);
//    }

    function testabc() {
        alert("hung");
    }

    function Dummy(selector) {
        alert("phuc");
    }

    window.Dummy = Dummy;
    Dummy.test = testabc();
//    Dummy.init();

})(window);
